using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SpringWaterDataAccess;

namespace admin
{
    public partial class ArticleEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlDataSource2.SelectCommand = "SELECT fp.Subject, fc.CategoryName,a.ArticleID, a.PostID, " +
                " a.Topic, a.SubTopic, a.BibleTitle, a.BibleChapter, a.BibleSection, a.BibleChapter_To, " + 
                " a.BibleSection_To, a.Vote_yes, a.Vote_no, a.ApproveOpinion, a.ApproveUserID, " + 
                " a.ApproveTime, a.URL FROM Article AS a LEFT OUTER JOIN ForumPosts AS fp ON a.PostID = fp.PostID  " +
                " Left Join ForumCategories fc on fp.CategoryID = fc.CategoryID ";
            SqlDataSource2.SelectParameters.Clear();

            string WhereOrAnd = " where ";
 
            if (TextBox1.Text != null && TextBox1.Text != "")
            {
                SqlDataSource2.SelectCommand += WhereOrAnd + " fp.Subject = @Subject";
                SqlDataSource2.SelectParameters.Add("Subject", TypeCode.String, TextBox1.Text.ToString());
                WhereOrAnd = " And ";
            }

            if (TextBox2.Text != null && TextBox2.Text != "")
            {
                SqlDataSource2.SelectCommand += WhereOrAnd + " a.Topic = @Topic";
                SqlDataSource2.SelectParameters.Add("Topic", TypeCode.String, TextBox2.Text.ToString());
                WhereOrAnd = " And ";
            }

            if (TextBox3.Text != null && TextBox3.Text != "")
            {
                SqlDataSource2.SelectCommand += WhereOrAnd + " a.SubTopic = @SubTopic";
                SqlDataSource2.SelectParameters.Add("SubTopic", TypeCode.String, TextBox3.Text.ToString());
               
            } 

        }

        protected void ArticleGridView_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {

        }

        protected void SqlDataSource2_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {

        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //ForumDataAccess sql = new ForumDataAccess();
            //DataSet dsPost = sql.getArticles();
            //ArticleGridView.DataSource = dsPost;
            //ArticleGridView.DataBind();

                //SqlDataSource2.SelectCommand = "SELECT fp.Subject, a.ArticleID, a.PostID, a.Topic, a.SubTopic, a.BibleTitle, a.BibleChapter, a.BibleSection, a.BibleChapter_To, a.BibleSection_To, a.Vote_yes, a.Vote_no, a.ApproveOpinion, a.ApproveUserID, a.ApproveTime, a.URL FROM Article AS a LEFT OUTER JOIN ForumPosts AS fp ON a.PostID = fp.PostID "
                //+ " where a.Topic = '" + TextBox2.Text + "'";
            

            ArticleGridView.DataBind();


        }
    }
}
